/*
 * @Author: nainaiyi s15037075861@163.com
 * @Date: 2022-09-05 11:09:18
 * @LastEditors: nainaiyi s15037075861@163.com
 * @LastEditTime: 2022-09-05 15:28:43
 * @FilePath: \购物车\shopapp\src\setupProxy.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
let { homeList } = require("./mock/index")

module.exports = (app) => {
    app.get("/api/home/list", (req, res) => {
        const { pageCode = 1, pageSize = 10, state } = req.query
        if (pageCode * pageSize <= homeList.length) {
            res.send({
                code: 200,
                data: homeList.slice((pageCode - 1) * pageSize, pageCode * pageSize)
            })
        } else {
            res.send({
                code: 404,
                data: null
            })
        }
    })
    app.get("/api/detail", (req, res) => {
        const { id } = req.query
        const item = homeList.find((v) => v.id === id)
        if (item) {
            res.send({
                code: 200,
                data: item
            })
        }

    })
}